# from icecream import ic
import json
import os
import sys
import pandas as pd
import requests

from get_sql_res import gen_run_detail, gen_data_cluster
from get_response import gen_wafermap_config_mapping,gen_wafermap_config
from gen_info_dic import gen_info_dic
from sheet_cover_page import gen_cover_page
from sheet_Summary import gen_Summary
from sheet_MAP import gen_MAP
from sheet_RsRuleSummary import gen_RsRuleSummary
from sheet_RsDieSummary import gen_RsDieSummary



directory_path = os.path.dirname(os.path.abspath(__file__))
file_path=os.path.join(directory_path,'cfgs/mapping_char.json')
with open(file_path, 'r',encoding='utf8') as file:
    rule_detail_maping = json.load(file)

def gen_dfs_base(df_run_detail, info_dic, sql_info,df_run_detail_raw):
    df_lst=gen_cover_page(info_dic, df_run_detail_raw)
    Summary_df=gen_Summary(df_run_detail, info_dic)
    MAP_df=gen_MAP(df_run_detail, info_dic)
    RsRuleSummary_df=gen_RsRuleSummary(info_dic, df_run_detail)
    RsDieSummary_df=gen_RsDieSummary(df_run_detail, info_dic, sql_info)
    return df_lst, Summary_df, MAP_df, RsRuleSummary_df, RsDieSummary_df


if __name__ == '__main__':
    from icecream import ic

    with open('./cfgs/input.json', 'r') as file:
        config = json.load(file)

    rule_run_record_id = config['recordId']
    sql_info = {}
    sql_info['mysqlInfo'] = config['mysqlInfo']
    sql_info['ckInfo'] = config['ckInfo']
    sql_info['dasHost'] = config['dasHost']
    re_file_path = config['fileFullPath']

    df_run_detail = gen_run_detail(rule_run_record_id, sql_info)


    info_dic=gen_info_dic(df_run_detail, sql_info)

    ##
    gen_dfs_base(df_run_detail, info_dic, sql_info)
